package homework;

import java.io.File;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;

import cn.hutool.core.io.FileUtil;

public class zy06 {
	public static void main(String[] args) {
		File name=FileUtil.file("..\\name1.txt");

		List<student> stu = FileUtil.readLines(name, "gbk").stream()
				.map(line -> line.split("-"))
				.map(parts -> new student(parts[0], parts[1], Integer.parseInt(parts[2]), parts[3]))
				.collect(Collectors.toList());
		System.out.println(stu);
		callName(stu, name);


	}
	private static void callName(List<student> stu,File name) {
		Random rc=new Random();
		int count=0;
		for(student s:stu){
			if(s.isFlage().equals("0")){
				count++;
			}
		}
		if(count==10){
			for(student s:stu){
				s.setFlage("1");
			}
			count=0;
			FileUtil.writeLines(stu, name, "gbk");
		}
        int[] arr=new int[stu.size()-count];
		int a=0;
		for(int i=0;i<stu.size();i++){
			if(stu.get(i).isFlage().equals("1")){
				arr[a]=i;
				a++;
			}
		}

		int index=rc.nextInt(arr.length);
		System.out.println(stu.get(arr[index]).toString());
		stu.get(arr[index]).setFlage("0");
		FileUtil.writeLines(stu, name, "gbk");
	}
}
